package com.example;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import com.example.config.AppConfig;
import com.example.service.UserService;

public class App {
    public static void main(String[] args) {
        System.out.println("=== Spring全注解配置演示程序 ===");
        
        // 1. 创建Spring容器，传入配置类
        AnnotationConfigApplicationContext context = 
            new AnnotationConfigApplicationContext(AppConfig.class);
        
        // 2. 从容器中获取Bean
        UserService userService = context.getBean(UserService.class);
        
        // 3. 使用Bean
        System.out.println("初始用户数: " + userService.getTotalUsers());
        
        // 注册用户
        userService.registerUser("张三", "zhangsan@example.com");
        userService.registerUser("李四", "lisi@example.com");
        
        // 查询用户信息
        System.out.println(userService.getUserInfo(1));
        System.out.println(userService.getUserInfo(2));
        System.out.println(userService.getUserInfo(99)); // 不存在的用户
        
        System.out.println("总用户数: " + userService.getTotalUsers());
        
        // 4. 关闭容器
        context.close();
        System.out.println("=== 程序执行完成 ===");
    }
}